/*******************************************************************************
* This file provides the functions for the UART module.
*
* Author: Kong Wai Weng
* Email:  waiweng83@gmail.com
*******************************************************************************/



#ifndef _HAL_UART_H
#define _HAL_UART_H



#include <uart.h>
#include "system.h"
#include "hal_gps.h"



/*******************************************************************************
* PUBLIC FUNCTION PROTOTYPES                                                   *
*******************************************************************************/

/*******************************************************************************
* PUBLIC FUNCTION: vInitUart1
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Initialize the UART 1 module.
* UART 1 is connected to the GPS.
*
*******************************************************************************/
void vInitUart1(void);



/*******************************************************************************
* PUBLIC FUNCTION: vWriteUart1
*
* PARAMETERS:
* ~ ucData	- The data to transmit.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Transmit a byte with UART 1.
* This is a blocking function.
*
*******************************************************************************/
void vWriteUart1(unsigned char ucData);



/*******************************************************************************
* PUBLIC FUNCTION: vInitUart2
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Initialize the UART 2 module.
* UART 2 is connected to the PC or telemetry device.
*
*******************************************************************************/
void vInitUart2(void);



/*******************************************************************************
* PUBLIC FUNCTION: vWriteUart2
*
* PARAMETERS:
* ~ ucData	- The data to transmit.
*
* RETURN:
* ~ void
*
* DESCRIPTIONS:
* Transmit a byte with UART 2.
* This is a blocking function.
*
*******************************************************************************/
void vWriteUart2(unsigned char ucData);



/*******************************************************************************
* PUBLIC FUNCTION: ucGetSendToPcSpace
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ Remaining space in SendToPc buffer.
*
* DESCRIPTIONS:
* Read the remaining empty space in the SendToPc buffer.
*
*******************************************************************************/
unsigned char ucGetSendToPcSpace(void);



/*******************************************************************************
* PUBLIC FUNCTION: ucSendToPc
*
* PARAMETERS:
* ~ pvBuffer	- The data to transmit.
* ~ ucLength	- The length of the data
*
* RETURN:
* ~ Number of bytes transmitted.
*
* DESCRIPTIONS:
* Transmit data to the PC.
*
*******************************************************************************/
unsigned char ucSendToPc(void* pvBuffer, unsigned char ucLength);



/*******************************************************************************
* PUBLIC FUNCTION: ucGetNumberOfBytesFromPc
*
* PARAMETERS:
* ~ void
*
* RETURN:
* ~ Number of bytes available in the ReceiveFromPc buffer.
*
* DESCRIPTIONS:
* Read the number of bytes available in the ReceiveFromPc buffer.
*
*******************************************************************************/
unsigned char ucGetNumberOfBytesFromPc(void);



/*******************************************************************************
* PUBLIC FUNCTION: ucReadFromPc
*
* PARAMETERS:
* ~ pvBuffer	- Buffer to store the received data.
* ~ ucLength	- The length of the data we want to read.
*
* RETURN:
* ~ Number of bytes read.
*
* DESCRIPTIONS:
* Receive data from PC.
*
*******************************************************************************/
unsigned char ucReadFromPc(void* pvBuffer, unsigned char ucLength);



#endif
